package com.yh.zz_hlj.modules.adatper;

import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.yh.zz_hlj.R;
import com.yh.zz_hlj.common.StringUtils;
import com.yh.zz_hlj.modules.bean.WorkInfo;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by john on 2016/7/23.
 */
public class UserPayAdapter extends ListBaseAdapter<WorkInfo>{
    static class ViewHolder {
        @InjectView(R.id.tv_ywy)
        TextView tv_ywy;
        @InjectView(R.id.tv_customername)
        TextView tv_customername;
        @InjectView(R.id.checkBox)
        CheckBox checkBox;
        @InjectView(R.id.tv_khname)
        TextView tv_khname;
        @InjectView(R.id.tv_title)
        TextView title;
        @InjectView(R.id.tv_description)
        TextView description;
        @InjectView(R.id.tv_time)
        TextView time;
        @InjectView(R.id.iv_statue)
        ImageView iv_statue;
        @InjectView(R.id.tv_user_pay)
        TextView tv_user_pay;
        public ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }

    @Override
    protected View getRealView(final int position, View convertView, ViewGroup parent) {
        ViewHolder vh = null;
        if (convertView == null || convertView.getTag() == null) {
            convertView = getLayoutInflater(parent.getContext()).inflate(
                    R.layout.list_item_user_pay, null);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }

        WorkInfo blog = mDatas.get(position);
        vh.title.setText(blog.getFpgNo());
//        if (blog.getFwgtype()){
//            vh.checkBox.setVisibility(View.GONE);
//        }else {
//            vh.checkBox.setVisibility(View.VISIBLE);
//            vh.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
//                @Override
//                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//                    mDatas.get(position).setFwgtype(isChecked);
//                }
//            });
//        }
//        vh.tv_index.setText(position+"");
        vh.description.setText(blog.getGYName());
        vh.tv_ywy.setText("数量:"+blog.getFQty()+"  单价:"+blog.getFPrice());
        vh.tv_user_pay.setText(blog.getFAmount()+"元");
//        vh.tv_ywy.setVisibility(View.GONE);
        vh.tv_customername.setVisibility(View.GONE);
        String time=blog.getFTime();
        if (!StringUtils.isEmpty(time)){
            if (time.indexOf(".")>-1) {
                vh.time.setText(time.replace("T", " ").substring(0, time.indexOf(".")));
            }else {
                vh.time.setText(time.replace("T", " "));
            }
        }else {
            String time1=blog.getFplanendDate();
            if (!StringUtils.isEmpty(time1)) {
                if (time1.indexOf(".") > -1) {
                    vh.time.setText(StringUtils.friendly_time(time1.replace("T", " ").substring(0, time1.indexOf("."))));
                } else {
                    vh.time.setText(StringUtils.friendly_time(time1.replace("T", " ")));
                }
            }else {
                vh.time.setVisibility(View.GONE);
            }
        }
        return convertView;
    }
}
